<template>
	<view>
		<view class="new-list">
			<scroll-view scroll-y="true" class="card-list" @scrolltolower="scrolltolower">
				<view class="card-warpper" v-for="(item,index) in videoList" :key="index">
					<view class="card-item" @click="videoShow(item)">
						<view class="card-item-thumb">
							<image :src="item.thumb" mode="aspectFill"></image>
							<view class="mask-bg">
							</view>
							<image class="mask-icon-pay" src="../../static/images/sign-in.png" mode=""></image>
						</view>
						<view class="card-item-title">
							{{item.title}}
						</view>
					</view>
				</view>
				<Loading :loaded="loaded" :loading="loading"></Loading>
			</scroll-view>
			<view style="opacity: 0;display: none;">
				<video controls id="myvideo" :src="videoUrl" @fullscreenchange="screenChange"></video>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		get_video_list
	} from '@/api/api.js';
	import IndexVideo from './components/indexVideo';
	import Loading from '@/components/Loading/index.vue';
	export default {
		components: {
			IndexVideo,
			Loading
		},
		data() {
			return {
				loaded: false,
				loading: false,
				quer: {
					page: 1,
					limit: 10
				},
				videoList: [],
				videoPlay: false,
				videoUrl: '',
				isBottom: false,
			};
		},
		onLoad() {

			this.getArticleHot()
		},
		onReady() {
			this.videoContext = uni.createVideoContext("myvideo", this);
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {

		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {

		},
		methods: {
			scrolltolower() {
				if (this.loaded) {
					return
				}
				this.loading = true
				this.getArticleHot()
				console.log('scrolltolower');
			},
			screenChange(e) {
				let fullScreen = e.detail.fullScreen; // 值true为进入全屏，false为退出全屏
				if (!fullScreen) {
					//退出全屏
					this.videoPlay = false; // 隐藏播放盒子
					this.videoContext.stop();
					this.videoUrl = '';
				}
			},
			// 触发全屏播放的点击事件
			videoShow(item) {
				console.log('===>==', item.url);
				let direction = 0
				// if(item.video_w>item.video_h){
				// 	direction = 90
				// }

				// this这个是实例对象 必传
				this.videoUrl = item.url;
				this.videoContext.requestFullScreen({
					direction: direction
				});
				setTimeout(() => {
					this.videoContext.play();
				}, 20)

				this.videoPlay = true; // 显示播放盒子
			},
			onDetail(item) {
				uni.navigateTo({
					url: '/pages/cardList/video/video?url=' + item.url
				})
			},
			getArticleHot: function() {
				let that = this;

				get_video_list(this.quer).then(res => {
					that.loading = false
					if (that.quer.page == 1) {
						that.$set(that, 'videoList', res.data.list);
					} else {
						that.$set(that, 'videoList', that.videoList.concat(res.data.list));
					}
					if (res.data.count / that.quer.limit > that.quer.page) {
						that.quer.page++
					} else {
						that.loaded = true;
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.new-list {
		background-image: url(../../static/images/Index_banner1.png);
		background-repeat: repeat-y !important;
		background-size: contain !important;
		background-position: center !important;

		.new-list-header {
			background-color: #fff;
		}

		.card-list {
			padding-top: 20rpx;
			height: 100vh;
			// position: fixed;
			// left: 0;
			// right: 0;
			// top: 0;
			// bottom: 0;

			.card-warpper {
				width: 50%;
				height: 400rpx;
				display: inline-block;
				padding: 10rpx 20rpx;
				box-sizing: border-box;
			}

			.card-item {
				background-color: #fff;
				width: 100%;
				height: 100%;
				border-radius: 10rpx;
				overflow: hidden;

				&-thumb {
					width: 100%;
					height: 300rpx;
					position: relative;

					.mask-bg {
						position: absolute;
						bottom: 0;
						left: 0;
						top: 0;
						right: 0;
						background-color: rgba(0, 0, 0, .5);
						z-index: 1;
					}
					.mask-icon-pay {
						width: 80rpx;
						height: 80rpx; 
						position: absolute;
						left: 50%;
						top: 50%;
						margin-top: -40rpx;
						margin-left: -40rpx;
						z-index: 2;
					}

					image {
						width: 100%;
						height: 100%;
						z-index: 0;
						position: relative;
					}
				}

				&-title {
					height: 80rpx;
					line-height: 80rpx;
					padding: 0 10rpx;
				}
			}
		}
	}
</style>
